home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_366 / ndebt / ndebt.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  169 lines

  1. /*
  2. Ndebt - display the national debt (approximately) in a small window.
  3.  
  4.                                 Ron Charlton
  5.                              9002 Balcor Circle
  6.                              Knoxville, TN 37923
  7.  
  8.                              Phone: (615)694-0800
  9.  
  10.                               PLINK: R*CHARLTON
  11.                            BINTNET: charltr@utkvx1
  12.  
  13.                                  05-Jul-90
  14.  
  15. This program is in the public domain.  It may be used for any purpose.
  16.  
  17. Will Run from Workbench and CLI.
  18.  
  19. History:
  20. v1.0   creation
  21. v1.1   convert to Manx Aztec C 5.0a
  22. */
  23.  
  24. char id [] = " Ndebt  by  Ron Charlton  V1.1  05-Jul-90 (public domain)";
  25.  
  26. #define INC 7673.015        /* delta debt per second */
  27. #include <stdio.h>
  28. #include <exec/types.h>
  29. #include <intuition/intuition.h>
  30. #include <time.h>
  31.  
  32. struct IntuitionBase *IntuitionBase;
  33.  
  34. struct Window *Wdw;
  35.  
  36. struct IntuiMessage *msg;
  37.  
  38. struct GfxBase *GfxBase;
  39.  
  40. #define Rp Wdw->RPort
  41.  
  42. struct NewWindow NewWdw = 
  43.    {
  44.    180, 15,            /* left, top              */
  45.    250 ,21,            /* width, height              */
  46.    0, 1,            /* DetailPen, BlockPen          */
  47.    CLOSEWINDOW,         /* IDCMP flags              */
  48.    WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG | ACTIVATE,  /* window flags */ 
  49.    NULL,            /* pointer to 1st gadget          */
  50.    NULL,            /* pointer to checkmark image      */
  51.    (void*)" USA National Debt",    /* title                  */
  52.    NULL,            /* pointer to screen structure, dummy */
  53.    NULL,            /* pointer to custom bit map      */
  54.    0,0,                /* minimum width, height          */
  55.    0,0,                /* maximum width, height          */
  56.    WBENCHSCREEN            /* type of screen              */
  57.    };
  58.  
  59. char buf [ 80 ] = "";
  60.  
  61. /* these are required by detach() */
  62. long _stack = 2000, _priority = 0, _BackGroundIO = 1;
  63. char *_procname = "NdebtProcess";
  64. /* end detach() stuff */
  65.  
  66. void _cli_parse(){} /* don't need it */
  67. void _wb_parse(){}  /* don't need it, either */
  68.  
  69. /* ========================< main >============================== */
  70.  
  71. main() 
  72.   {
  73.   time_t time();
  74.   double debt;
  75.   time_t now;
  76.  
  77.   /* =-=-= open everything =-=-= */
  78.   IntuitionBase = (struct IntuitionBase *)
  79.                        OpenLibrary("intuition.library",0);
  80.   if (IntuitionBase == NULL)
  81.        quit ();
  82.  
  83.   GfxBase = (struct GfxBase *)
  84.     OpenLibrary("graphics.library",0);
  85.   if (GfxBase == NULL)
  86.     quit();
  87.  
  88.   if (( Wdw = (struct Window *)OpenWindow(&NewWdw)) == NULL )
  89.        quit ();
  90.  
  91.   SetWindowTitles ( Wdw, -1, id );
  92.   SetAPen ( Rp, 1 );
  93.   SetBPen ( Rp, 0 );
  94.  
  95.   time ( &now );
  96.   if ( now < 300000000L ) /* before about 12/88 */
  97.     {
  98.     Move ( Rp, 37, 17 );
  99.     Text ( Rp, "Set DATE/TIME first.", 20 );
  100.     for (;;)
  101.       {
  102.       msg = (struct IntuiMessage *) GetMsg ( Wdw -> UserPort );
  103.       if ( msg != NULL ) /* we got the big CLOSEWINDOW */
  104.     {
  105.         ReplyMsg ( msg );
  106.     quit ();
  107.     }
  108.       }
  109.     }
  110.  
  111.   buf [ 0 ] = '$';
  112.   for (;;)    /* main loop */
  113.     {
  114.     msg = (struct IntuiMessage *) GetMsg ( Wdw -> UserPort );
  115.     if ( msg != NULL ) /* we got the big CLOSEWINDOW */
  116.     {
  117.         ReplyMsg ( msg );
  118.     break;
  119.     }
  120.     time ( &now );
  121.     /* 
  122.      * As of 12/31/88: debt = $2,707,284,000,000 & rate = $7673.015/sec.
  123.      * Source - Survey of Current Business, c. January 1989.
  124.      *
  125.      * The following assumes 'now' is in seconds since 01-Jan-1970 (v5.0a).
  126.      */
  127.     debt = now * INC - 1.893579e12;
  128.     sprintf ( buf+1, "%.0f", debt );
  129.     addcommas ( buf );
  130.     Move ( Rp, 37, 17 );
  131.     Text ( Rp, buf, strlen ( buf ) );
  132.     Delay ( 50L );
  133.     }
  134.     quit ();
  135. }
  136.  
  137. /* 
  138.  * add commas to an ASCII number in string s
  139.  */
  140. addcommas ( s )
  141.   char *s;
  142.   {
  143.   char work [ 80 ], *w;
  144.   int len = strlen ( s ), i;
  145.   w = work;
  146.   for ( i = 0; i < len; i++ )
  147.     {
  148.     if ( !(i % 3) && i )
  149.       *w = ',', ++w;
  150.     *w = s [ len - i - 1 ];
  151.     ++w;
  152.     }
  153.   *w = '\0';
  154.   /* reverse the string */
  155.   for ( i = strlen ( work ); i > 0; i-- )
  156.     *s++ = work [ i - 1 ];
  157.   *s = '\0';
  158.   }
  159.  
  160. quit()
  161.   {
  162.   if ( Wdw )           CloseWindow  ( Wdw );
  163.   if ( GfxBase )       CloseLibrary ( GfxBase );
  164.   if ( IntuitionBase ) CloseLibrary ( IntuitionBase );
  165.   exit(0);
  166.   }
  167.  
  168.  
  169.